package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class AlbumInfoApiController {

	@Autowired
	private AlbumInfoService albumInfoService;
	@GuiGuLogin
	@Operation(summary = "新增专辑")
	@PostMapping("/saveAlbumInfo")
	public Result saveAlbumInfo(@RequestBody AlbumInfoVo albumInfoVo){
		albumInfoService.saveAlbumInfo(albumInfoVo);
		return Result.build(null, ResultCodeEnum.SUCCESS);
	}
	@GuiGuLogin
	@Operation(summary = "查询当前用户专辑分页列表")
	@PostMapping("/findUserAlbumPage/{page}/{limit}")
	public Result<IPage<AlbumListVo>> findUserAlbumPage(@PathVariable(value = "page") Integer pageNo,
														@PathVariable(value = "limit") Integer pageSize,
														@RequestBody AlbumInfoQuery albumInfoQuery
														){
		IPage<AlbumListVo> albumListVoIPage = albumInfoService.findUserAlbumPage(pageNo,pageSize,albumInfoQuery);
		return Result.build(albumListVoIPage,ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "根据id删除专辑")
	@DeleteMapping("/removeAlbumInfo/{id}")
	public Result removeAlbumInfo(@PathVariable Integer id){
		albumInfoService.removeAlbumInfo(id);
		return Result.build(null,ResultCodeEnum.SUCCESS);
	}

	@Operation(summary = "根据专辑id获取专辑信息")
	@GetMapping("/getAlbumInfo/{id}")
	public Result getAlbumInfo(@PathVariable(value = "id") Long albumId){
		AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
		return Result.build(albumInfo,ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "根据id修改专辑")
	@PutMapping("/updateAlbumInfo/{id}")
	public Result updateAlbumInfo(@PathVariable(value = "id") Integer albumId,@RequestBody AlbumInfoVo albumInfoVo){
		albumInfoService.updateAlbumInfo(albumId,albumInfoVo);
		return Result.build(null,ResultCodeEnum.SUCCESS);
	}

	@GuiGuLogin
	@Operation(summary = "获取当前用户全部专辑列表")
	@GetMapping("/findUserAllAlbumList")
	public Result<List<AlbumInfo>> findUserAllAlbumList(){
		List<AlbumInfo>albumInfoList = albumInfoService.findUserAllAlbumList();
//		List<AlbumInfo>albumInfoList = albumInfoService.findUserAllAlbumList(AuthContextHolder.getUserId());
		return Result.build(albumInfoList,ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "获取专辑统计数据")
	@GetMapping("/getAlbumStatVo/{albumId}")
	public Result<AlbumStatVo> getAlbumStatVo(@PathVariable Long albumId){
		AlbumStatVo albumStatVo = albumInfoService.getAlbumStatVo(albumId);
		return Result.build(albumStatVo,ResultCodeEnum.SUCCESS);
	}
}

